package com.bw.mallshop.mvvm.model;

import com.bw.common.entity.BaseEntity;
import com.bw.common.mvvm.model.BaseModel;
import com.bw.common.network.HttpType;
import com.bw.common.network.RetrofitFactory;
import com.bw.mallshop.entity.CategoryEntity;
import com.bw.mallshop.entity.CategoryValueEntity;
import com.bw.mallshop.repository.ApiService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;

public class CategoryModel extends BaseModel {

    //当前界面正常情况下有2个接口:左侧类别接口，右侧列表接口
    //当前界面接口为测试数据所以只具有右侧列表接口;
    //规范请求:先获取左侧接口列表数据在根据左侧列表中第0条数据得id
    //获取右侧列表数据,每次点击左侧列表中一条item数据，请求一次右侧列表中数据
    //同一条item 多次点击只请求第一次
    private String[]names={"电脑办公","手机数码","男装","女装","家用电器"};

    //获取左侧列表数据->本地添加虚拟数据
    public List<CategoryEntity>requestCategory(){
        List<CategoryEntity> list = new ArrayList<>();
        for (int i = 0;i < names.length;i ++){
            CategoryEntity entity = new CategoryEntity(i,names[i]);
            if (i == 0)
                entity.selFlag = true;
            list.add(entity);
        }
        return list;
    }
    //获取右侧列表数据->根据parentID(左侧得虚拟数据)获取接口数据
    public Observable<BaseEntity>requestCategoryValue(Map<String,Object>parames){
        Observable<CategoryValueEntity>observable = RetrofitFactory.factory(HttpType.TOKENSIGN)
                .createRetrofit().create(ApiService.class).requestCategoryValue(createBody(parames));
        return changeObservable(observable);
    }
}
